#include <fcntl.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include "file_fd.h"

#define BUF_SIZE 1024

int filefdTest(void) {
    int fd = open("example.txt", O_RDONLY);
    if(-1 == fd) {
        perror("open Error:");
        return -1;
    }
    char buf[BUF_SIZE];
     ssize_t ret = read(fd,  buf, sizeof(char)*(BUF_SIZE-1));
     buf[BUF_SIZE-1] = 0;
     if(-1 == ret) {
        perror("read error:");
        close(fd);
        return -1;
     }
     printf("get buf: %s\n", buf);
    close(fd);
    return 0;
}

int main() {
    filefdTest();
    return 0;
}
